<?php
namespace app\api\model;
use \think\Model;

class EcmsNews extends Model{

    public function getNewsList($p = null,$col=null,$limit=10,$field=""){

        if($col == null){
            return false;
        }
        $cols = \think\Config::get('cols');
        if(is_array($cols) && isset($cols[$col])){
            $where = "where";
            if(is_array($cols[$col])){
                //如果是多栏目
                foreach ($cols[$col] as $value) {
                    $where .= " `classid`={$value} OR";
                }
                $where = rtrim($where,"OR");
            }else{
                //单栏目
                $where .= " `classid`={$cols[$col]}";
            }
        }else{
            return false;
        }

        if(!is_numeric($p) || $p < 0){
            $start = 0;
        }else{
            $start = $p * $limit;
        }
        $news = "SELECT id,title,newstime{$field} FROM `www_ecms_news` {$where} order by istop DESC,firsttitle DESC,id DESC LIMIT {$start},{$limit}";

        $res = sql_to_data($news);

        return $res;
    }

    public function getGoodList($limit=10,$field=''){

        if(!is_numeric($limit)){
            $limit = 5;
        }
        $news = "SELECT id,title,newstime,titlepic{$field} FROM `www_ecms_news` WHERE `isgood`=1 order by istop DESC,firsttitle DESC,id DESC LIMIT {$limit}";

        $res = sql_to_data($news);

        return $res;
    }

}
